Repository navigation
feat: implement ai asistant in local ollama - #49
Open
danielgarciaperal2001-glitch wants to merge 1 commit into
Open
danielgarciaperal2001-glitch wants to merge 1 commit into
danielgarciaperal2001-glitch wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
The AI assistant was hard-wired to the Anthropic SDK. This makes it a small provider layer so the backend and the model can be picked at runtime from the AI widget: Claude stays the default and behaves exactly as before, and a local Ollama model can be used instead — no API key, nothing leaving the machine.
New server/src/ai/ module with one file per backend (anthropic.ts, ollama.ts) behind a shared AiProvider contract; Claude's existing behaviour (default model, thinking: adaptive, refusal handling) is moved over unchanged.
GET /api/ai/providers and GET /api/ai/models?provider= added; POST /api/ai/chat now accepts optional provider and model and falls back to Claude when they're omitted, so existing clients keep working.
The AI widget gets a backend dropdown, a model dropdown (populated live from the Ollama daemon) and a reload button; the choice is persisted in the existing Zustand store. The AI ●/○ indicator in the top bar now reflects whether any backend is usable.
Optional config: OLLAMA_BASE_URL (default http://127.0.0.1:11434/) and OLLAMA_MODEL; also wired into docker-compose.yml.
Security: the browser never contacts Ollama and cannot supply a URL — the API server resolves the base URL from the environment, so this can't be turned into an SSRF proxy. The new endpoints sit behind the existing API key and rate limit.
Testing: npm test -w server (35 passed, incl. 9 new tests for the AI routes), npm run build -w server, npm run build -w web all pass. Also verified end-to-end against a local Ollama daemon: switching the dropdown lists the installed models and a question is answered by the local model using the live terminal context.
Note: this contribution was developed with an AI coding agent and reviewed, built and tested by a human.